<!--
 * @Author: June
 * @Date: 2022-11-17 10:27:53
 * @LastEditors: 无处安放的六月 547293866@qq.com
 * @LastEditTime: 2023-11-27 10:31:47
 * @Description:
 *
-->
<template>
  <el-dropdown trigger="click" @command="handleSetSize">
    <div>
      <!-- <i class="iconfont icon-font-size" icon-class="size" /> -->
      <svg v-if="layoutSettings" class="icon" aria-hidden="true">
        <use xlink:href="#icon-zitidaxiao" />
      </svg>
      <i v-else class="iconfont icon-fontsize" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of sizeOptions" :key="item.value" :disabled="size === item.value" :command="item.value">
        {{ item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  props: {
    layoutSettings: false
  },
  data() {
    return {
      sizeOptions: [
        { label: 'Default', value: 'default' },
        { label: 'Medium', value: 'medium' },
        { label: 'Small', value: 'small' },
        { label: 'Mini', value: 'mini' }
      ]
    }
  },
  computed: {
    size() {
      return this.$store.getters.size
    }
  },
  methods: {
    handleSetSize(size) {
      this.$ELEMENT.size = size
      this.$store.dispatch('app/setSize', size)
      this.refreshView()
      this.$message({
        message: 'Switch Size Success',
        type: 'success'
      })
    },
    refreshView() {
      // In order to make the cached page re-rendered
      this.$router.push('/reload')
    }
  }
}
</script>
<style scoped>
.icon {
  width: 28px;
  height: 70px;
}
.icon-fontsize {
  font-size: 20px;
}
</style>
